<?php

class EProductImage extends DataObject {
    static $db = array(
        'Title' => 'Text',
        'SortOrder' => 'Int'
    );
    static $has_one = array(
        'Image' => 'Image',
        'ThumbNail' => 'Image',
        'EProduct' => 'EProduct'
    );
    public static $default_sort = 'SortOrder';
    function getCMSFields() {
        $fields = new FieldList(new TabSet('Root'));

        $fields->addFieldsToTab('Root.Main', array(
            new TextField('Title'),
            new UploadField('ThumbNail','Thumb(359x271)'),
            new UploadField('Image','Image')
        ));
        return $fields;
    }
    static $summary_fields = array(
        'thumb' => 'ThumbNail',
        'Title' => 'Title'
    );
    function thumb() {
        return $this->ImageID != 0 ? $this->Image()->CMSThumbnail() : 'no-image';
    }
}